<template>
  <div class="box">
    <header class="header">
      <van-nav-bar
        left-arrow
        title="新增地址"
        @click-left="$router.back()"
      />
    </header>
    <div class="cont">
      <van-address-edit
        :area-list="areaList"
        show-postal
        show-delete
        delete-button-text="取消"
        show-set-default
        show-search-result
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        @delete="onDelete"
      />
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { AddressEdit, NavBar } from 'vant'
import { addAddress } from '../../api/index.js'

Vue.use(AddressEdit)
Vue.use(NavBar)
export default {
  data () {
    return {
      areaList: {
        province_list: {
          110000: '北京市',
          120000: '天津市'
        },
        city_list: {
          110100: '北京市',
          110200: '县',
          120100: '天津市',
          120200: '县'
        },
        county_list: {
          110101: '东城区',
          110102: '西城区',
          110105: '朝阳区',
          110106: '丰台区',
          120101: '和平区',
          120102: '河东区',
          120103: '河西区',
          120104: '南开区',
          120105: '河北区'
        }
      }
    }
  },
  methods: {
    onSave (v) {
      // console.log(v)
      const address = v.province + v.city + v.county + v.addressDetail
      // console.log(address)
      // const arr = [{
      //   address: address,
      //   tel: v.tel,
      //   isDefault: v.isDefault,
      //   name: v.name
      // }]
      // userId,userName,tel,addressDetail,Postal
      addAddress({
        userId: localStorage.getItem('userId'),
        addressDetail: address,
        userName: v.name,
        tel: v.tel,
        Postal: 475300
      }).then(data => {
        console.log(data)
        this.$router.push('/addressList?id=' + this.$route.query.id)
      })
    },
    onDelete (v) {
      // console.log(v)
      if (this.$route.query.id) {
        this.$router.push('/addressList?id=' + this.$route.query.id)
      } else {
        this.$router.push('/addressList')
      }
    }
  }
}
</script>

<style>
</style>
